package org.xs.big_event.dao.category;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Optional;

public interface CategoryRepository extends JpaRepository<Category, Integer> {
    //查看用户所有文章类别
    @Query(value = "select * from category where create_user=?1",nativeQuery = true)
    ArrayList<Category> findAllclassByUser(Integer createUser);
    //根据id查看类别
    @Query(value = "select * from category where id=?1",nativeQuery = true)
    Optional<Category> findail(Integer id);
    //更新文章分类
    @Modifying
    @Transactional
    @Query(value = "update category set category_name=?1,category_alias=?2,update_time=?3 where id=?4",nativeQuery = true)
    void updateCategory(String categoryName,String categoryAlias,LocalDateTime updateTime, Integer id);
}
